package text;

import mapper.TeacherMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import pojo.Person;
import pojo.Teacher;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Test {
    private InputStream inputStream;
    private SqlSessionFactory factory;
    private SqlSession session;

    @Before
    public void before() throws IOException {
        //通过IO流获取核心配置文件
        InputStream inputStream= Resources.getResourceAsStream("sqlMapConfig.xml");
        //获取数据源
        SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(inputStream);
        //打开sqlsession对象
        session=factory.openSession();

    }
    @org.junit.Test
    public void test01(){
        List<Person> list= session.selectList("pojo.PersonMapper.findAll");
        for(Person person:list){
            System.out.println(person);
        }
    }
    @org.junit.Test
    public void test02(){
        TeacherMapper teacherMapper=session.getMapper(TeacherMapper.class);
        List<Teacher> list=session.selectList("mapper.TeacherMapper.findTeacherAll");
        for (Teacher teacher:list){
            System.out.println(teacher);
        }
    }
}





















































